<template>
    <div class="safeResponsibility">
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>单位层级</label>
            </div>
            <group>
                <popup-picker :data="companyTierArr"
                              placeholder='默认全部'
                              v-model="companyTier"
                              @on-change="onPullingDown"></popup-picker>
            </group>
        </div>
        <h2>数量:{{listAllCount}} </h2>
        <noData v-if="listAllCount == 0"></noData>
        <div class="bscroll1">
            <vue-better-scroll class="wrapper"
                               ref="scroll"
                               :scrollbar="scrollbarObj"
                               :pullDownRefresh="pullDownRefreshObj"
                               :pullUpLoad="pullUpLoadObj"
                               :startY="parseInt(startY)"
                               @pullingDown="onPullingDown"
                               @pullingUp="onPullingUp">
                <div class="bscroll-container">
                    <ul class="lists">
                        <li v-for="(item,index) in list"
                            :key="index">
                            <router-link :to="{
                                name:'responsibilityDetail',
                                params:{
                                    DutyName:item.DutyName,
                                    DutyContent:item.DutyContent
                                }
                            }">
                                <div>
                                    <p>{{item.DutyName}}</p>
                                </div>
                                <div class="status">
                                    <x-icon type="ios-arrow-right"
                                            size="26"
                                            class="icon-right"
                                            fill="#999"></x-icon>
                                </div>
                            </router-link>
                        </li>
                    </ul>
                </div>
            </vue-better-scroll>
        </div>
        <myMenu></myMenu>
    </div>
</template>
<script>
import myMenu from '@/commonComponents/menu'
import VueBetterScroll from 'vue2-better-scroll'
export default {
    name: 'safeResponsibility',
    components: {
        myMenu,
        VueBetterScroll
    },
    data () {
        return {
            userInfo: {},
            // dropDown: false
            // 这个配置可以开启滚动条，默认为 false。当设置为 true 或者是一个 Object 的时候，都会开启滚动条，默认是会 fade 的
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: {
                threshold: 90,
                stop: 40
            },
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            scrollToX: 0,
            scrollToY: 0,
            scrollToTime: 700,
            list: [],
            listAllCount: 0,
            listCount: 0,
            companyTierArr: [['项目部层级', '分子公司层级', '公司层级']],
            companyTier: [],
            deptsir: '0'// 单位层级，公司级0，分公司级11，项目级1
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
        switch (this.userInfo.departsir) {
            case '0':
                this.companyTier = ['公司层级']
                break
            case '1':
                this.companyTier = ['项目部层级']
                break
            case '11':
                this.companyTier = ['分子公司层级']
                break
            default:
                break
        }
    },
    mounted () {
        this.onPullingDown()
    },
    methods: {
        onPullingDown () {
            switch (this.companyTier[0]) {
                case '公司层级':
                    this.deptsir = '0'
                    break
                case '项目部层级':
                    this.deptsir = '1'
                    break
                case '分子公司层级':
                    this.deptsir = '11'
                    break
                default:
                    break
            }
            this.pageIndex = 0
            this.list = []
            this.getData()
        },
        onPullingUp () {
            this.pageIndex++
            this.getData()
        },
        getData () {
            let params = {
                'business': 'getSafeDutyList',
                'data': {
                    'deptsir': this.deptsir, // 单位层级，公司级0，分公司级11，项目级1
                    'dutyname': ''// 名称搜索
                },
                'pageIndex': this.pageIndex,
                'pageSize': 10
            }

            this.$axiosAjax.getConfigJson(params)
                .then((res) => {
                    if (res.data.code === 0) {
                        this.list = this.list.concat(res.data.data.rows)
                        this.listAllCount = res.data.data.total
                        this.listCount = this.list.length
                    }
                    if (this.listCount < this.listAllCount) {
                        this.$refs.scroll.forceUpdate(true)
                    } else {
                        this.$refs.scroll.forceUpdate(false)
                    }
                }).catch((response) => {
                })
        }
    }
}
</script>
<style scoped>
.safeResponsibility h2 {
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-align: right;
    padding-right: 20px;
    box-sizing: border-box;
    background: #ebeef2;
}
.safeResponsibility .bscroll1 {
    position: absolute;
    top: 95px;
    bottom: 0;
    left: 0;
    right: 0;
    overflow: hidden;
}
.lists {
    padding-left: 20px;
}
.lists a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px 14px 0;
    border-bottom: 1px solid #efeff4;
    font-size: 14px;
    color: #333;
}
.lists p {
    font-size: 14px;
    color: #333;
    line-height: 18px;
}
</style>
